package com.first.agent.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.first.agent.common.JsonResult;
import com.first.agent.service.impl.CustomerServiceImp;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/customer/search")
public class SearchCustomerServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String customerName= request.getParameter("customer_name");
        Integer page = Integer.parseInt(request.getParameter("page"));
        Integer pageSize = Integer.parseInt(request.getParameter("limit"));
        //调用service
        CustomerServiceImp csi=new CustomerServiceImp();
        JsonResult jsonResult = csi.customerTable(page, pageSize, customerName);

        //响应
        response.setContentType("application/json;charset=utf-8");
        PrintWriter pw = response.getWriter();
        pw.write(JSONObject.toJSONString(jsonResult));
        pw.flush();
        pw.close();


    }
}
